/*
 * @[H]:  Copyright (c) 2021 Phytium Information Technology, Inc. 
 * 
 *  SPDX-License-Identifier: Apache-2.0. 
 * 
 * @Date: 2021-08-17 17:18:16
 * @LastEditTime: 2021-08-18 16:02:14
 * @Description:  Description of file
 * @Modify History: 
 * * * Ver   Who        Date         Changes
 * * ----- ------     --------    --------------------------------------
 */
#include "fgdma.h"
#include "fgdma_hw.h"

ft_error_t FGdmaSetOption(FGdma *instance_p, u32 options)
{
    u32 reg_value;
    FT_ASSERTNONVOID(instance_p != NULL);
    FT_ASSERTNONVOID(instance_p->is_ready == FT_COMPONENT_IS_READY);

    switch (options)
    {
    case FGDMA_OP_WRITE_QOS_MODE:
        reg_value = FGDMA_READREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET);
        reg_value |= FGDMA_GLOBAL_CTL_WR_ARB_MASK;
        FGDMA_WRITEREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET, reg_value);
        break;
    case FGDMA_OP_READ_QOS_MODE:
        reg_value = FGDMA_READREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET);
        reg_value |= FGDMA_GLOBAL_CTL_RD_ARB_MASK;
        FGDMA_WRITEREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET, reg_value);
        break;
    default:
        return FGMDA_ERR_OP;
    }

    return FT_SUCCESS;
}

ft_error_t FGdmaClearOption(FGdma *instance_p, u32 options)
{
    u32 reg_value;
    FT_ASSERTNONVOID(instance_p != NULL);
    FT_ASSERTNONVOID(instance_p->is_ready == FT_COMPONENT_IS_READY);

    switch (options)
    {
    case FGDMA_OP_WRITE_QOS_MODE:
        reg_value = FGDMA_READREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET);
        reg_value &= ~FGDMA_GLOBAL_CTL_WR_ARB_MASK;
        FGDMA_WRITEREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET, reg_value);
        break;
    case FGDMA_OP_READ_QOS_MODE:
        reg_value = FGDMA_READREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET);
        reg_value &= ~FGDMA_GLOBAL_CTL_RD_ARB_MASK;
        FGDMA_WRITEREG(instance_p->config.base_address, FGDMA_GLOBAL_CTL_OFFSET, reg_value);
        break;
    default:
        return FGMDA_ERR_OP;
    }

    return FT_SUCCESS;
}
